/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rhdtp.demopf.control.admin;

import com.rhdtp.demopf.model.dao.ActorDAO;
import com.rhdtp.demopf.model.dao.ClienteDAO;
import com.rhdtp.demopf.model.dao.DirectorDAO;
import com.rhdtp.demopf.model.dao.PeliculaDAO;
import com.rhdtp.demopf.model.dao.PrestamoDAO;
import com.rhdtp.demopf.model.dao.UsuarioDAO;
import com.rhdtp.demopf.model.dto.Actor;
import com.rhdtp.demopf.model.dto.Cliente;
import com.rhdtp.demopf.model.dto.Director;
import com.rhdtp.demopf.model.dto.Pelicula;
import com.rhdtp.demopf.model.dto.Prestamo;
import com.rhdtp.demopf.model.dto.Usuario;
import com.rhdtp.demopf.security.UserSession;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.apache.log4j.Logger;
import org.primefaces.context.RequestContext;

/**
 *
 * @author rhdtp
 */
public class HomeAdmin {

    private static final Logger logger = Logger.getLogger(HomeAdmin.class);
    private ActorDAO actorDAO;
    private ClienteDAO clienteDAO;
    private DirectorDAO directorDAO;
    private PeliculaDAO peliculaDAO;
    private PrestamoDAO prestamoDAO;
    private UsuarioDAO usuarioDAO;
    private UserSession userSession;
    private List<Prestamo> adeudosFilter;
    private Pelicula test;

    public HomeAdmin() {
    }    

    public void resetForm() {
        initObjects();
        RequestContext.getCurrentInstance().reset("registro:formulario");
    }    

    public void devolucion(Prestamo p){
        p.setEstatus(2);
        prestamoDAO.update(p);
        msgInfo("Info.", "Registro de devolución exitoso");
    }

    @PostConstruct
    public void initObjects() {
    }

    public void msgInfo(String summary, String detail) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

    public void msgError(String summary, String detail) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

    public void msgWarning(String summary, String detail) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_WARN, summary, detail);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
    
    public List<Prestamo> getAdeudos(){
        return prestamoDAO.adeudos();
    }

    public List<Cliente> getClientes() {
        return clienteDAO.list();
    }    
    
    public List<Actor> getActors(){
        return actorDAO.list();
    }
    
    public List<Director> getDirectors(){
        return directorDAO.list();
    }
    
    public List<Pelicula> getPeliculas(){
        return peliculaDAO.list();
    }
    
    public List<Prestamo> getPrestamos(){
        return prestamoDAO.list();
    }
    
    public List<Usuario> getUsuarios(){
        return usuarioDAO.list();
    }

    /**
     * @param clienteDAO the clienteDAO to set
     */
    public void setClienteDAO(ClienteDAO clienteDAO) {
        this.clienteDAO = clienteDAO;
    }

    public UserSession getUserSession() {
        return userSession;
    }

    public void setUserSession(UserSession userSession) {
        this.userSession = userSession;
    }

    public PeliculaDAO getPeliculaDAO() {
        return peliculaDAO;
    }

    public void setPeliculaDAO(PeliculaDAO peliculaDAO) {
        this.peliculaDAO = peliculaDAO;
    }

    public PrestamoDAO getPrestamoDAO() {
        return prestamoDAO;
    }

    public void setPrestamoDAO(PrestamoDAO prestamoDAO) {
        this.prestamoDAO = prestamoDAO;
    }

    public ActorDAO getActorDAO() {
        return actorDAO;
    }

    public void setActorDAO(ActorDAO actorDAO) {
        this.actorDAO = actorDAO;
    }

    public DirectorDAO getDirectorDAO() {
        return directorDAO;
    }

    public void setDirectorDAO(DirectorDAO directorDAO) {
        this.directorDAO = directorDAO;
    }

    public UsuarioDAO getUsuarioDAO() {
        return usuarioDAO;
    }

    public void setUsuarioDAO(UsuarioDAO usuarioDAO) {
        this.usuarioDAO = usuarioDAO;
    }

    public List<Prestamo> getAdeudosFilter() {
        return adeudosFilter;
    }

    public void setAdeudosFilter(List<Prestamo> adeudosFilter) {
        this.adeudosFilter = adeudosFilter;
    }

    public Pelicula getTest() {
        return test;
    }

    public void setTest(Pelicula test) {
        this.test = test;
    }
}
